import com.v3webservice.service.V3webservice;
import com.v3webservice.util.WebServiceUtils;
import org.apache.http.util.EntityUtils;
import org.dom4j.DocumentHelper;
import org.jsoup.Jsoup;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.*;

public class v3Test {
    @Test
    public void test() throws Exception {

//        SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHHmmss");
//        Date date  = sd.parse("20210107103000");
//        System.out.println(date);

//        Date data1 = new Date();
//        System.out.println(data1.toString());

        V3webservice v3webservice = new V3webservice();
        v3webservice.accessService(null,"");
    }

    @Test
    public void webServiceTest()
    {
        ResourceBundle bundle = ResourceBundle.getBundle("v3webservice");
        boolean isPushAsn = Boolean.valueOf(bundle.getString("isPushAsn")).booleanValue();
        if (isPushAsn) {
            String wsdl = bundle.getString("wsdl");
            String method = bundle.getString("pushAsnMethod");
            String ns = bundle.getString("namespace");
            String docType = bundle.getString("docType");
            String docTypeParam = bundle.getString("docTypeParam");
            String updateType = bundle.getString("updateType");
            String updateTypeParam = bundle.getString("updateTypeParam");
            String inputDtoXml = bundle.getString("inputDtoXml");
            String result = bundle.getString("result");

            System.out.println("webService--->" + wsdl);
            System.out.println("method--->" + method);
            System.out.println("namespace-->" + ns);
            System.out.println("docType--->" + docType);
            System.out.println("docTypeParam--->" + docTypeParam);
            System.out.println("updateType--->" + updateType);
            System.out.println("updateTypeParam--->" + updateTypeParam);
            System.out.println(inputDtoXml);
            System.out.println("result-->" + result);

            Map param = new HashMap();
            param.put(docType, docTypeParam);
            param.put(updateType, updateTypeParam);

            List asnList = new ArrayList();

            param.put(inputDtoXml, WebServiceUtils.getXmlStr(asnList));
            System.out.println("inputDtoXml:");
            System.out.println((String)param.get(inputDtoXml));
            System.out.println("param:" + param.toString());

            String responseWeb = "";
            try {
                responseWeb = WebServiceUtils.accessService(wsdl, ns, method, param, result);
//                System.out.println("responseWeb:" + responseWeb);
//                System.out.println(Jsoup.parse(responseWeb));
//                String responseEntity = EntityUtils.toString(responseWeb.getEntity(),"UTF-8");
//                System.out.println(WebServiceUtils.xmlToJson(DocumentHelper.parseText(responseEntity)));
            } catch (Exception e) {
                System.out.println(e.toString());
            }
        }
    }
}
